﻿using System;
using System.IO;
using System.Net;
using System.Xml.Serialization;

namespace SverigesRadio.SverigesRadioApp.Business
{
    public class ServiceCallerEventArgs<T> : EventArgs
    {
        public ServiceCallerEventArgs(DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                Error = e.Error;
                return;
            }

            XmlSerializer serializer = new XmlSerializer(typeof(T));
            ServiceResult = (T)serializer.Deserialize(new StringReader(e.Result));
        }

        public Exception Error
        {
            get;
            private set;
        }

        public T ServiceResult
        {
            get;
            private set;
        }
    }
}
